package com.sunxcloud.rabbitmq.producer;

import com.sunxcloud.common.core.constant.IProcessor;
import com.sunxcloud.common.core.producer.service.ProducerService;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 生产者消息接口实现
 */
@EnableBinding(IProcessor.class)
public class ProducerServiceImpl implements ProducerService {

    @Resource(name = IProcessor.OUTPUT_MESSAGE)
    private MessageChannel messageChannel;

    @Override
    public String send() {
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String message = "生产者消息发送："+sdf.format(new Date());
        messageChannel.send(MessageBuilder.withPayload(message).build());
        return message;
    }
}
